<template ref="asd">
  <div>
    <div class="header">
      <p class="title">
        <span>Cards</span>
        <span>View all cards</span>
      </p>
      <div class="cards">
        <div
          class="cardItem"
          v-for="item in cards"
          :key="item.id"
          :style="'backgroundColor:' + item.bgcolor + ';color:' + item.color"
        >
          <section class="first">
            <p>Available balance</p>
            <p>{{item.balance}}</p>
          </section>
          <p class="account">{{item.account}}</p>
          <section class="last">
            <span>Monzo</span>
            <el-switch v-model="item.info" @click="toggle(item.state)"></el-switch>
          </section>
        </div>
        <div class="addcard" @click="addCard">
          <p>
            <i class="el-icon-circle-plus-outline"></i>
            <span>Add New Card</span>
          </p>
        </div>
      </div>
    </div>
    <div class="massageCont">
      <div class="butCon">
        <p>
          <span>Main Services</span>
          <span>View all</span>
        </p>
        <div class="showMassgeBtn">
          <el-button plain v-for="item in buttonMassage" :key="item.id">
            <i :class="item.icon"></i>
            <span>{{item.title}}</span>
          </el-button>
        </div>
      </div>
      <div class="dataCon">
        <div class="current">
          <p>
            <span>Current</span>
            <span>View all</span>
          </p>
          <p class="asd">
            <span>1051115115</span>
            <i></i>
            <span>$2,200.01</span>
          </p>
          <p>
            <span>1051115115</span>
            <i></i>
            <span>$1,300.89</span>
          </p>
          <p>
            <span>1051115115</span>
            <i></i>
            <span>$1848.11</span>
          </p>
        </div>
        <div class="echarts">
          <p class="headertitle">
            <span>Savings</span>
            <span>View all</span>
          </p>
          <div class="condata">
            <div id="main" style="width: 400px;height:250px;"></div>
            <div class="histroymassage">
              <p>
                <span>Total</span>
                <span>$100.09</span>
              </p>
              <p>
                <span>This week</span>
                <span>$2567.89</span>
              </p>
              <p>
                <span>This month</span>
                <span>$123.09</span>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 添加卡片的弹窗 -->
    <el-dialog title="添加银行卡" :visible.sync="addCardinfo" width="30%">
      <!-- 表单验证输入 -->
      <el-form :model="addruleForm" :rules="rules" ref="ruleForm" label-width="100px">
        <el-form-item label="银行卡账号" prop="name">
          <el-input v-model="addruleForm.name"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="region">
          <el-input v-model="addruleForm.region"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addCardinfo = false">取 消</el-button>
        <el-button type="primary" @click="addCardinfo = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import echarts from 'echarts'
export default {
  data () {
    var checkMobile = (rule, value, cb) => {
      const regMobile = /^(0|86|17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]14[57])[0-9]{8}/
      if (regMobile.test(value)) {
        return cb()
      }
      cb(new Error('请输入合法的手机号码'))
    }
    return {
      cards: [
        {
          id: 1,
          balance: '$2,200',
          account: '****  ****  ****  **34',
          bgcolor: '#ff4d56',
          color: '#d4222b',
          state: true
        },
        {
          id: 2,
          balance: '$1,300.89',
          account: '****  ****  ****  **67',
          bgcolor: '#0e809a',
          color: '#084a57',
          state: true
        }
      ],
      addCardinfo: false,
      addruleForm: {
        name: '',
        region: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入银行卡账号', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请输入手机号码', trigger: 'blur' },
          { validator: checkMobile, trigger: 'blur' }
        ]
      },
      buttonMassage: [
        {
          id: 1,
          icon: 'el-icon-sort',
          title: 'Transactions'
        },
        {
          id: 2,
          icon: 'el-icon-s-opportunity',
          title: 'Utility'
        },
        {
          id: 3,
          icon: 'el-icon-s-claim',
          title: 'Loans'
        },
        {
          id: 4,
          icon: 'el-icon-s-finance',
          title: 'Deposits'
        },
        {
          id: 5,
          icon: 'el-icon-timer',
          title: 'Fast transfer'
        },
        {
          id: 6,
          icon: 'el-icon-rank',
          title: 'Exchange'
        }
      ]
    }
  },
  methods: {
    toggle (state) {
      state = !state
    },
    addCard () {
      this.addCardinfo = !this.addCardinfo
    }
  },
  mounted () {
    var myChart = echarts.init(document.getElementById('main'))
    var option = {
      tooltip: {},
      legend: {
        data: ['']
      },
      xAxis: {
        data: ['$10', '$20', '$30', '$40', '$50']
      },
      yAxis: {},
      series: [
        {
          name: '',
          type: 'line',
          data: [3, 16, 12, 36, 20, 40]
        }
      ]
    }
    myChart.setOption(option)
  }
}
</script>
<style lang="less" scoped>
.title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin: 0 0 30px 0;
  span:first-child {
    font-weight: bold;
  }
  span:last-child {
    color: #ccc;
  }
}
.cards {
  display: flex;
  width: 100%;
  height: 174px;
  justify-content: space-between;
  .cardItem {
    width: 300px;
    height: 174px;
    border-radius: 20px;
    .first {
      padding-left: 28px;
      margin-top: 20px;
      p:first-child {
        font-size: 12px;
      }
      p:last-child {
        margin-top: 5px;
        color: white;
        font-size: 16px;
      }
    }
    .account {
      margin-top: 22px;
      padding-left: 28px;
      height: 38px;
      line-height: 38px;
      font-size: 16px;
    }
    .last {
      display: flex;
      padding-left: 28px;
      padding-right: 16px;
      height: 38px;
      line-height: 38px;
      justify-content: space-between;
      align-items: center;
      span {
        color: white;
      }
    }
  }
}
.addcard {
  width: 300px;
  height: 174px;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: #ccc;
  background-color: #f8f8f8;
  border-radius: 20px;
  p {
    display: flex;
    width: 200px;
    height: 60px;
    flex-direction: column;
    text-align: center;
    .el-icon-circle-plus-outline {
      color: #ccc;
      font-size: 40px;
    }
    span {
      width: 200px;
    }
  }
}
.massageCont {
  display: flex;
  width: 100%;
  margin-top: 66px;
  justify-content: space-between;
  .butCon {
    width: 260px;
    p {
      display: flex;
      justify-content: space-between;
      width: 100%;
      margin: 0 0 30px 0;
      span:first-child {
        font-weight: bold;
      }
      span:last-child {
        color: #ccc;
      }
    }
    .showMassgeBtn {
      display: flex;
      width: 100%;
      height: 400px;
      justify-content: space-between;
      align-items: space-between;
      flex-wrap: wrap;
      .el-button {
        display: flex;
        width: 120px;
        height: 120px;
        align-items: center;
        justify-content: center;
        margin: 0;
        border: none;
        box-shadow: 22px 18px 14px 0 #f7f8fa;
        border-radius: 22px;
        span {
          display: flex;
          width: 100%;
          flex-direction: column;
          i {
            color: #ff4d56;
            font-size: 30px;
          }
          span {
            margin-top: 20px;
            color: black;
            font-size: 16px;
          }
        }
      }
    }
  }
}
.current {
  width: 600px;
  height: 150px;
  p {
    display: flex;
    justify-content: space-between;
    height: 36px;
    margin-bottom: 4px;
    span:first-child {
      color: #ccc;
    }
    span:nth-child(2) {
      color: #ccc;
    }
    i {
      box-sizing: border-box;
      width: 334px;
      height: 30px;
      border-bottom: 1px dashed #ccc;
    }
  }
}
.asd {
  margin-top: 22px;
}
.echarts {
  margin-top: 50px;
  width: 600px;
  height: 200px;
  .headertitle {
    display: flex;
    width: 100%;
    height: 26px;
    justify-content: space-between;
    span:nth-child(2) {
      color: #ccc;
    }
  }
}
.condata{
  position: relative;
  margin-top: 20px;
  .histroymassage{
    position: absolute;
    width: 190px;
    height: 100px;
    top: 0;
    right: 0;
    p{
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;
      span:first-child{
        color: #ccc;
      }
    }
  }
}
#main{
  position: absolute;
  top: -50px;
  left: -20px;
}
</style>
